package mc

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"runtime"
)

//统一错误处理中间件
func MiddlewareRecover(c *gin.Context) {
	defer func() {
		if err := recover(); err != nil {
			// 统一错误处理
			var buf [4096]byte
			n := runtime.Stack(buf[:], false)
			SetStackErr(c, fmt.Sprintf("%s STACK: \n%s", err, string(buf[:n])))
			AbortWithError(c, err)
		}
	}()
	c.Next()
}
